package gamesys.games.particlesystem.effects
{
	import gamesys.games.particlesystem.core.ParticleData;
	import gamesys.games.particlesystem.utils.Range;

	public class GroundEffect implements IEffect
	{
		private var _ground:Range;
		private var _elastisity:Range;

		public function GroundEffect(ground:Range, elastisity:Range)
		{
			_elastisity = elastisity;
			_ground = ground;
		}

		public function reset(particleData:ParticleData):void
		{
			particleData.ground = _ground.range;
			particleData.elastisity = _elastisity.range;
		}

		public function update(particleData:ParticleData):void
		{
			if (particleData.y > particleData.ground)
			{
				particleData.xSpeed *= particleData.elastisity;
				particleData.ySpeed *= particleData.elastisity;
				particleData.ySpeed = -particleData.ySpeed;

				particleData.y = particleData.ground - (particleData.y - particleData.ground);
			}
		}
	}
}
